<?php

class Admin_Form_Event extends Zend_Form {

    private $id; // l'id de l'utilisateur

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function init() {
// le nom du formulaire
        $this->setName('formEvent');
        $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);

//element hidden id pour l'utilisation du formulaire lors de la modification d'un utilisateur
        $id = new Zend_Form_Element_Hidden('id');

//element texte firstname
        $owner_firstname = new Zend_Form_Element_Text('owner_firstname');
        $owner_firstname->setLabel('form_event_owner_firstname')
                ->setRequired(true)
                ->addValidator('notEmpty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');
        $owner_name = new Zend_Form_Element_Text('owner_name');
        $owner_name->setLabel('form_event_owner_name')
                ->setRequired(true)
                ->addValidator('notEmpty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

//element texte date
        $date = new Zend_Form_Element_Text('date');
        $date->setLabel('form_event_date')
                ->setRequired(true)
                ->addValidator('notEmpty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

        $title = new Zend_Form_Element_Text('title');
        $title->setLabel('form_event_title')
                ->setRequired(true)
                ->addValidator('notEmpty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

//element texte conteny
        $content = new Zend_Form_Element_Textarea('event_content');
        $content->setLabel('form_event_content')
                ->setRequired(true)
                ->addValidator('notEmpty');
//                ->addFilter('StripTags')
//                ->addFilter('StringTrim');

        $image = new Zend_Form_Element_File('image');
        $image->setLabel('form_event_image')
                ->setDestination("/var/www/appliweb/public/images/")
                ->setMaxFileSize(2097152);
        $image->addValidator('Count', false, 1);
        $image->addValidator('Size', false, 2097152);
        $image->addValidator('Extension', false, 'jpg,jpeg,png,gif')
                ->addValidator('notEmpty');

//bouton submit
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id', 'submitbutton')
                ->setLabel('form_user_submit');

// on ajoute tous les éléments du formulaire dans un tableau
        $elements = array($id, $owner_firstname, $owner_name, $title, $date, $content, $image, $submit);

// on ajoute ce tableau d'éléments au formulaire
        $this->addElements($elements);

        $id = $this->getId();
        if (isset($id) && $id != "") {
            $mod = new Application_Model_EventModel ( );
            $eventFound = $mod->read($id)->toArray();
            if ($eventFound != null) {
                $this->populate($eventFound);
            } else {
                throw new Zend_Exception("form_user_no_id");
            }
        }
    }

}

